/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.projects.toolbox_basics_project.bean;

import java.util.Locale;

import com.genia.toolbox.basics.i18n.SupportedLanguage;
import com.genia.toolbox.projects.toolbox_basics_project.spring.manager.LanguageManager;

/**
 * A container for a
 * {@link com.genia.toolbox.projects.toolbox_basics_project.bean.model.Language}
 * that allows to stock it even if the hibernate session is closed.
 */
public class LanguageContainter
    implements SupportedLanguage
{

  /**
   * the identifier of the
   * {@link com.genia.toolbox.projects.toolbox_basics_project.bean.model.Language}
   * to stock.
   */
  private Long identifier;

  /**
   * the {@link LanguageManager} to use.
   */
  private LanguageManager languageManager;



  /**
   * returns the {@link SupportedLanguage} that is used as a delegate.
   * 
   * @return the {@link SupportedLanguage} that is used as a delegate
   */
  private SupportedLanguage getLanguage()
  {
    return getLanguageManager().getLanguage(identifier);
  }



  /**
   * getter for the identifier property.
   * 
   * @return the identifier
   */
  public Long getIdentifier()
  {
    return identifier;
  }



  /**
   * setter for the identifier property.
   * 
   * @param identifier
   *          the identifier to set
   */
  public void setIdentifier(Long identifier)
  {
    this.identifier = identifier;
  }



  /**
   * getter for the languageManager property.
   * 
   * @return the languageManager
   */
  public LanguageManager getLanguageManager()
  {
    return languageManager;
  }



  /**
   * setter for the languageManager property.
   * 
   * @param languageManager
   *          the languageManager to set
   */
  public void setLanguageManager(LanguageManager languageManager)
  {
    this.languageManager = languageManager;
  }



  /**
   * getter for the locale property.
   * 
   * @return the locale property.
   * @see com.genia.toolbox.basics.i18n.SupportedLanguage#getLocale()
   */
  public Locale getLocale()
  {
    return getLanguage().getLocale();
  }



  /**
   * Return the order value of this object, with a higher value meaning greater
   * in terms of sorting.
   * 
   * @return the order value
   * @see org.springframework.core.Ordered#getOrder()
   */
  public int getOrder()
  {
    return getLanguage().getOrder();
  }



  /**
   * Returns a hash code value for the object. This method is supported for the
   * benefit of hashtables such as those provided by
   * <code>java.util.Hashtable</code>.
   * 
   * @return a hash code value for this object.
   * @see java.lang.Object#hashCode()
   */
  @Override
  public int hashCode()
  {
    return getLanguage().hashCode();
  }



  /**
   * Indicates whether some other object is "equal to" this one.
   * 
   * @param obj
   *          the reference object with which to compare.
   * @return <code>true</code> if this object is the same as the obj argument;
   *         <code>false</code> otherwise.
   * @see java.lang.Object#equals(java.lang.Object)
   */
  @Override
  public boolean equals(Object obj)
  {
    if (this == obj)
      return true;
    if (obj == null)
      return false;
    if (getClass() != obj.getClass())
      return false;
    final LanguageContainter other = (LanguageContainter) obj;
    return getLanguage().equals(other.getLanguage());
  }
}
